﻿using System;
using System.Windows.Forms;

namespace Client.Forms
{
    public partial class WaitForm : Form
    {
        Action<string> setMSG;
        Action close;

        public WaitForm()
        {
            InitializeComponent();
            setMSG = invoke;
            close = base.Close;
        }

        public string msg
        {
            get
            {
                return label1.Text;
            }
            set
            {
                while (!this.IsHandleCreated) ;
                this.Invoke(setMSG, value);
            }
        }
        public new void Close()
        {
            while (!this.IsHandleCreated) ;
            this.Invoke(close);
        }
        private void invoke(string msg)
        {
            this.label1.Text = msg;
            this.AccessibleName = msg;
            this.Text = msg;
        }
        private void WaitForm_Shown(object sender, EventArgs e)
        {
            this.Focus();
        }

        private void Label1_TextChanged(object sender, EventArgs e)
        {
            label1.Location = new System.Drawing.Point((this.Size.Width - label1.Size.Width) / 2, (this.Size.Height - label1.Size.Height) / 2);
        }
    }
}
